package org.dtrd.config.wechat.entity.bean.officialaccount.template;

import lombok.Data;
import org.dtrd.common.util.DateUtils;
import org.dtrd.config.common.PathUtil;
import org.dtrd.config.wechat.entity.bean.officialaccount.WechatOaTemplateMsg;

/**
 * @author xiao
 * @date 2022/5/31 3:44 PM
 */
@Data
public class ServiceStateMsg extends WechatOaTemplateMsg {

    /**
     * 服务类型
     */
    private String serviceType;

    /**
     * 服务状态
     */
    private String handleState;

    public static final class ServiceStateMsgBuilder {
        private ServiceStateMsg serviceStateMsg;

        private ServiceStateMsgBuilder() {
            serviceStateMsg = new ServiceStateMsg();
        }

        public static ServiceStateMsgBuilder singleInstance() {
            return new ServiceStateMsgBuilder();
        }

        public ServiceStateMsgBuilder withMsgTitle(String msgTitle) {
            serviceStateMsg.setMsgTitle(msgTitle);
            return this;
        }

        /**
         * 配置给医生的复诊预约成功消息
         *
         * @param patientName
         * @param appointTime
         * @param patientId
         * @param flupId
         * @return
         */
        public ServiceStateMsgBuilder buildFlupAppointForDoctor(String patientName, String appointTime, Integer patientId, Integer flupId) {
            return buildFlupAppoint(String.format("您的患者%s复诊预约成功", patientName), appointTime, patientId, flupId,"doctor");
        }

        /**
         * 配置给患者的毒针预约成功消息
         *
         * @param appointTime
         * @param patientId
         * @param flupId
         * @return
         */
        public ServiceStateMsgBuilder buildFlupAppointForPatient(String appointTime, Integer patientId, Integer flupId) {
            return buildFlupAppoint("您的复诊预约已成功", appointTime, patientId, flupId,"patient");
        }

        /**
         * 配置复诊预约成功消息
         *
         * @param msgTitle
         * @param appointTime
         * @param patientId
         * @param flupId
         * @return
         */
        private ServiceStateMsgBuilder buildFlupAppoint(String msgTitle, String appointTime, Integer patientId, Integer flupId,String from) {
            this.withMsgTitle(msgTitle).withServiceType("复诊预约")
                    .withHandleState("已成功").withMsgTime(DateUtils.formatDate(DateUtils.datetime_sdf_wz.get().toPattern()))
                    .withRemark(String.format("预约的时间最终确定为%s，点击查看复诊详情", appointTime))
                    .withUrl(PathUtil.getH5Domain() + "/patient/follow/notVisitRecord.html?userid=" + patientId + "&flupid=" + flupId + "&from=" + from);
            return this;
        }

        /**
         * 配置给医生得复诊结束消息
         *
         * @param patientName
         * @param patientId
         * @param flupId
         * @param doctorId
         * @return
         */
        public ServiceStateMsgBuilder buildFlupAppointFinishForDoctor(String patientName, Integer patientId,Integer doctorId, Integer flupId) {
            return buildFlupAppointFinish(String.format("您的患者%s已成功完成复诊", patientName), patientId, doctorId,flupId, "doctor");
        }

        public ServiceStateMsgBuilder buildFlupAppointFinishForPatient(Integer patientId, Integer flupId) {
            return buildFlupAppointFinish("您已完成复诊", patientId,0, flupId, "patient");
        }

        private ServiceStateMsgBuilder buildFlupAppointFinish(String msgTitle, Integer patientId, Integer doctorId,Integer flupId, String from) {
            this.withMsgTitle(msgTitle).withServiceType("复诊")
                    .withHandleState("完成").withMsgTime(DateUtils.formatDate(DateUtils.datetime_sdf_wz.get().toPattern()))
                    .withRemark("点击查看复诊详情").withUrl(PathUtil.getH5Domain() + "/patient/follow/notVisitRecord.html?userid=" + patientId + "&flupid=" + flupId + "&from=" + from + "&doctorId=" + doctorId);
            return this;
        }

        /**
         * {{first.DATA}}
         * 服务类型：{{keyword1.DATA}}
         * 服务状态：{{keyword2.DATA}}
         * 服务时间：{{keyword3.DATA}}
         * {{remark.DATA}}
         *
         * @param msgTitle
         * @param serviceItemName
         * @param patientId
         * @param serviceId
         * @param from
         * @return
         */
        private ServiceStateMsgBuilder buildServiceItemStateChange(String msgTitle, String serviceItemName, String remark, Integer patientId,Integer doctorId, Integer serviceId, String from) {
            this.withMsgTitle(msgTitle).withServiceType(serviceItemName)
                    .withHandleState("完成").withMsgTime(DateUtils.formatDate(DateUtils.datetime_sdf_wz.get().toPattern()))
                    .withRemark(remark).withUrl(PathUtil.getH5Domain() + "/patient/hMService/service.html?userid=" + patientId + "&packageid=" + serviceId + "&from=" + from+ "&doctorId=" + doctorId);
            return this;
        }

        /**
         * 您已完成服务
         * 服务类型：服务项名称
         * 服务状态：完成
         * 服务时间：2022-05-21 11:20
         * 点击进行服务评价
         *
         * @param serviceItemName
         * @param patientId
         * @param serviceId
         * @return
         */
        public ServiceStateMsgBuilder buildServiceItemStateChangeForPatient(String serviceItemName, Integer patientId, Integer serviceId) {
            return buildServiceItemStateChange("您已完成服务", serviceItemName, "点击进行服务评价", patientId,0, serviceId, "patient");
        }

        /**
         * 您的患者XXX已完成服务
         * 服务类型：服务项名称
         * 服务状态：完成
         * 服务时间：2022-05-21 11:20
         * 点击查看服务详情
         *
         * @param patientName
         * @param serviceItemName
         * @param patientId
         * @param serviceId
         * @return
         */
        public ServiceStateMsgBuilder buildServiceItemStateChangeForDoctor(String patientName, String serviceItemName, Integer patientId, Integer doctorId,Integer serviceId) {
            return buildServiceItemStateChange(String.format("您的患者%s已成功完成服务", patientName), serviceItemName, "点击查看服务详情", patientId, doctorId,serviceId, "doctor");
        }

        /**
         * 构造患者基础信息已填写消息
         * <p>
         * 您已完成基本信息填写
         * 服务类型：基本信息
         * 服务状态：成功
         * 服务时间：2022-05-21 11:20
         * 点击立即联系您的医生
         *
         * @param infoType
         * @param url
         * @return
         */
        public ServiceStateMsgBuilder buildPatientBasicInfoMsg(String infoType, String url, String remark) {
            this.withMsgTitle("您已完成基本信息填写").withServiceType(infoType)
                    .withHandleState("成功").withMsgTime(DateUtils.formatDate(DateUtils.datetime_sdf_wz.get().toPattern()))
                    .withRemark(remark).withUrl(url);
            return this;
        }


        public ServiceStateMsgBuilder withUrl(String url) {
            serviceStateMsg.setUrl(url);
            return this;
        }

        public ServiceStateMsgBuilder withRemark(String remark) {
            serviceStateMsg.setRemark(remark);
            return this;
        }

        public ServiceStateMsgBuilder withMsgTime(String msgTime) {
            serviceStateMsg.setMsgTime(msgTime);
            return this;
        }

        public ServiceStateMsgBuilder withReceiverOpenIdArray(String... receiverOpenIdArray) {
            serviceStateMsg.setReceiverOpenIdArray(receiverOpenIdArray);
            return this;
        }

        public ServiceStateMsgBuilder withServiceType(String serviceType) {
            serviceStateMsg.setServiceType(serviceType);
            return this;
        }

        public ServiceStateMsgBuilder withHandleState(String handleState) {
            serviceStateMsg.setHandleState(handleState);
            return this;
        }

        public ServiceStateMsg build() {
            return serviceStateMsg;
        }
    }
}
